﻿using ErgoBreak.Data;
using System.ComponentModel;

namespace ErgoBreak.Core
{
    public sealed class ConfigurationManager
    {
        #region Fields
        private IUpdatableController controller;
        private ObserverFactory obsFactory;
        #endregion

        #region Events

        #endregion

        #region Constructors
        internal ConfigurationManager(Settings appSettings, IUpdatableController mainController, ObserverFactory factory)
        {
            // initializations
            this.controller = mainController;
            this.obsFactory = factory;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Binds the current object to the given Settings object
        /// </summary>
        /// <param name="settings">The Settings object to be bound to</param>
        public void Bind(Settings settings)
        {
            // wire up the handler
            settings.PropertyChanged += new PropertyChangedEventHandler(ManagePropertyChanged);
        }
        #endregion

        #region Non-Public Methods
        private void ManagePropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "Observer":
                    this.controller.UpdateObserver(this.obsFactory.CreateObserver());
                    break;
            }
        }
        #endregion
    }
}
